package com.cjbdi.service;

//姝姐编写，用于高院检索

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.hibernate.SQLQuery;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class TestJDBCService{
	@Autowired  
    @PersistenceContext  
    private EntityManager entityManager;// 注入EntityManager实例 

	/*public String getResult(){  
		//entityManager.getTransaction().begin();
		SessionImplementor session = entityManager.unwrap(SessionImplementor.class);
		Connection connection = session.connection();
		Statement statement;
		String result="";
		try {
			statement = connection.createStatement();
			String sql = "select * from gonggao";
			
			ResultSet rs = statement.executeQuery(sql);
			while (rs.next()) {
				rs.getString("tag");
				result = rs.getString(1);

			}
			rs.close();
			statement.close();
			//connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return result;
    }*/
	public List getResult(){  
		Query query = entityManager.createNativeQuery("select * from gonggao");  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }
	
}
